package vn.com.bookstore.model;

import vn.com.bookstore.Config;
import vn.com.bookstore.ObjectStore;
import android.util.Log;

import com.google.gson.Gson;

// Page class
@SuppressWarnings("serial")
public class Page extends ObjectStore {
	public static final String TAG = "page";

	public int id = -1;
	public int page = 0;
	public String title = "";
	public String content = "";

	public Page(int id, int page, String title, String content) {
		this.id = id;
		this.page = page;
		this.content = content;
		this.title = title;
	}

	public static Page createDataSample(int i) {
		return new Page(i, i, "chapter: " + i, "Client, This is content of chapter. It is verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry loooooooooooooooooooooooooong");
	}

	public static Page parseGson(String json) {
		Gson gson = new Gson();
		Page page = (Page) gson.fromJson(json, Page.class);
		return page;
	}

	public boolean isImage() {
		if (content != null && content.startsWith("img/") && (content.toLowerCase().endsWith(".jpg") || content.toLowerCase().endsWith(".png") || content.toLowerCase().endsWith(".jpeg") || content.toLowerCase().endsWith(".gif")))
			return true;
		else
			return false;
	}

	public String getImageLink() {
		Log.e("Page", "content: " + content + " isImage: " + isImage());
		if (isImage()) {
			String url = content.replace("img/", "");
			return url;
		} else {
			return "";
		}
	}
}